import http from '@/utils/request'

/**
 * 获取所有角色列表
 * @param {*} page 页码
 * @param {*} pagesize 每页条数
 */
export const reqGetRoleList = (page = 1, pagesize = 5) => {
  return http({
    method: 'get',
    url: '/sys/role',
    params: {
      page,
      pagesize
    }
  })
}

/**
 * 添加角色
 * @param {*} form {name, description}
 */
export const reqAddRole = (form) => {
  return http({
    method: 'post',
    url: '/sys/role',
    data: form
  })
}

/**
 * 删除角色 传递id
 */
export const reqDelRole = (id) => {
  return http({
    method: 'delete',
    url: `/sys/role/${id}`
  })
}

/**
 * 根据角色的id获取角色详情
 */
export const reqGetRoleDetail = (id) => {
  return http({
    method: 'get',
    url: `/sys/role/${id}`
  })
}

/**
 * 更新角色详情(form中需要有id以及其他信息)
 */
export const reqUpdateRole = (form) => {
  return http({
    method: 'put',
    url: '/sys/role/' + form.id,
    data: form
  })
}

/**
 * 给角色分配权限
 * @param {*} id 角色id
 * @param {*} permIds 权限id的数组
 */
export function reqAssignPerm(id, permIds) {
  return http({
    method: 'put',
    url: '/sys/role/assignPrem',
    data: {
      id,
      permIds
    }
  })
}
